/*===========================================================
 
 .---=||||[ B L O O D Y ]|||||=====================----------....
 |                                                              |
 |    THE  M O S T   B L O O D Y  GAME EVER!                    |
 |                                                              |
 |    bloody harvest is coming... soon,                         |
 |                                              heil Satan!     |
 !                                                              !
 .                                                              ,
  ~~~~-------------================================|||||||||==-~




 Name-Space: {core, logic, editor}
 Module: {draw, coll, scgr, ...}
 Class: <name of class>
 Last modification:  <author>, <time>

 TODO:
 <-------- todo #1 ---------->
 <-------- todo #2 ---------->
 <-------- todo #3 ---------->
        ............
 <-------- todo #n ---------->

 FIX:
 <-------- fix #1 ----------->
 <-------- fix #1 ----------->
         ..........
 <-------- fix #n ----------->




 
 
 ============================================================*/
#include "core/Timer.h"

namespace core
{

	Timer* Timer::inst = 0;

	Timer::Timer()
	{
		//double time = SDL_GetTicks() * 0.001;
		pauseDelta = 0;
		pauseStart = 0;
		isPaused = false;
	}

	Timer& Timer::instance()
	{
		if (!inst)
		{
			inst = new Timer();
		}
		return *inst;
	}

	void Timer::pause()
	{
		if (isPaused) return;
		pauseStart = SDL_GetTicks() * 0.001;
		isPaused = true;
	}

	void Timer::unpause()
	{
		if (!isPaused) return;
		double time = SDL_GetTicks() * 0.001;
		pauseDelta += time - pauseStart;
		isPaused = false;
	}

	double Timer::getTime() const
	{
		double now = SDL_GetTicks() * 0.001;
		//cerr << "time:" << now << "=" << now - pauseDelta << endl;
		return now - pauseDelta;
	}



}
